/*
 * @Author: Bo Cai
 * @Mail: caibo0520@qq.com
 * @Date: 2021-11-20 14:42:29
 * @LastEditors: Bo Cai
 * @LastEditTime: 2021-12-20 10:49:20
 */
import axios from 'axios'
import cookie from 'js-cookie'

const service = axios.create({
  baseURL: process.env.baseUrl,
  timeout: 10000
})
service.interceptors.request.use(
  config => {
    if (cookie.get('qingdong_token')) {
      config.headers['token'] = cookie.get('qingdong_token')
    }
    return config
  },
  err => {
    return Promise.reject(err)
  })
service.interceptors.response.use(
  response => {
    if (response.data.success == false && response.data.error == 'AuthFailure') {
      window.location.href = '/login'
      return
    } else {
      return response
    }
  },
  error => {
    return Promise.reject(error.response)   // 返回接口返回的错误信息
  })
export default service
